#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>

#define MAXLEN 100 

using namespace std;

struct String {
    wchar_t data[MAXLEN]; 
    size_t length;
};

void InitString(String* S, const wchar_t* chars) {
    size_t len = wcslen(chars);
    if (len > MAXLEN)
        exit(EXIT_FAILURE); 
    wcscpy_s(S->data, chars);
    S->length = len;
}

void StrInsert(String* S, String* S1, size_t i) {
    if (i < 1 || i > S->length + 1) {
        wcout << L"Invalid position for insertion" << endl;
        return;
    }
    if (S->length + S1->length > MAXLEN - 1) {
        wcout << L"Exceeding maximum string length" << endl;
        return;
    }
    for (size_t j = S->length; j >= i; j--) {
        S->data[j + S1->length] = S->data[j];
    }
    for (size_t j = 0; j < S1->length; j++) {
        S->data[i - 1 + j] = S1->data[j];
    }
    S->length += S1->length;
}

void StrDelete(String* S, size_t i, size_t l) {
    if (i < 1 || i > S->length || i + l - 1 > S->length) {
        wcout << L"Invalid position for deletion" << endl;
        return;
    }
    for (size_t j = i - 1; j + l < S->length; j++) {
        S->data[j] = S->data[j + l];
    }
    S->length -= l;
}

int main() {
    String S, S1;
    InitString(&S, L"Hello, world!");
    InitString(&S1, L"beautiful ");
    StrInsert(&S, &S1, 7);
    wcout << L"After insertion: " << S.data << endl;
    StrDelete(&S, 7, 10);
    wcout << L"After deletion: " << S.data << endl;

    return 0;
}
